//
// Created by 沈航烨 on 2024/10/31.
//

#include "FFmplayer.h"

#include <SDLRender.h>

void FFmplayer::Init(char *url, int renderType) {
    m_VideoDecoder = new VideoDecoder(url);
    if(renderType == VIDEO_RENDER_SDL) {
        VideoRender *video_render=new SDLRender();
        m_VideoDecoder->SetVideoRender(video_render);
    }
    m_VideoDecoder->SetMessageCallback(this, PostMessage);


}

void FFmplayer::PostMessage(void *context, int msgType, float msgCode) {

    printf("%d %d",msgType,msgCode);
//    printf("")


}

long FFmplayer::GetMediaParams(int paramType) {

//     long value = 0;
//     switch(paramType)
//     {
//         case MEDIA_PARAM_VIDEO_WIDTH:
//             value = m_VideoDecoder != nullptr ? m_VideoDecoder->GetVideoWidth() : 0;
//         break;
//         case MEDIA_PARAM_VIDEO_HEIGHT:
//             value = m_VideoDecoder != nullptr ? m_VideoDecoder->GetVideoHeight() : 0;
//         break;
//         case MEDIA_PARAM_VIDEO_DURATION:
//             value = m_VideoDecoder != nullptr ? m_VideoDecoder->GetDuration() : 0;
//         break;
//     }
//     return value;
// }

    return 0;
}

void FFmplayer::SeekToPosition(float position) {
    if(m_VideoDecoder)
        m_VideoDecoder->SeekToPosition(position);

}

void FFmplayer::Stop() {
    if(m_VideoDecoder)
        m_VideoDecoder->Stop();

}

void FFmplayer::Pause() {
    if(m_VideoDecoder)
        m_VideoDecoder->Pause();

}

void FFmplayer::Play() {

    if(m_VideoDecoder)
        m_VideoDecoder->Start();

}


void FFmplayer::UnInit() {

    if(m_VideoDecoder) {
        delete m_VideoDecoder;
        m_VideoDecoder = nullptr;
    }

    if(m_VideoRender) {
        delete m_VideoRender;
        m_VideoRender = nullptr;
    }


}
